package com.eascs.ant.user.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.ant.common.controller.BaseMasterViewController;
import com.eascs.ant.user.entity.Team;
import com.eascs.ant.user.service.TeamItemService;
import com.eascs.ant.user.service.TeamService;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;

@Controller
public class TeamViewController extends BaseMasterViewController {

	@Inject
	private TeamService teamService;

	@Inject
	private TeamItemService teamItemService;

	@RequestMapping(value = "/user/team/view")
	public String viewTeam() {
		List<Team> teams = this.teamService.getAllTeam();
		for (Team team : teams) {
			PaginationInfo paginationInfo = new PaginationInfo(teamItemService.getTeamItemViewByTeamCode(team.getCode()), new String[] { "成员" });
			paginationInfo.setSelectDataOptions(new SelectDataOption[] { new SelectDataOption("allUser", "user") });
			paginationInfo.setMoreButtons(new Button[] { ButtonHelper.createAjaxConfirmButton("移除", "/user/team-item/delete?id=") });
			ViewContext.put("paginationInfo" + team.getCode(), paginationInfo);
		}
		ViewContext.put("teams", teams);
		return "user/team/view";
	}

}
